package com.common;
import java.util.Timer;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.common.SearchIndex;

import com.common.GlobalSetting;

public class HjqServletContextListener implements ServletContextListener {
	
	private ServletContext context = null;
	private Timer timer = null;
	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		System.out.println("===========HjqServletContextListener===========shutdown=============");	
		timer.cancel();
	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		context = sce.getServletContext();
		//get project root path
		Constant.SYSTEMPATH=context.getRealPath("/");
		Constant.INDEX_PATH=context.getRealPath("/")+"searchindex";
		String webpath = GlobalSetting.getProperty("webpath");
		context.setAttribute("webpath", webpath);
		System.out.println("===========HjqServletContextListener===========startup=============");
		
		//定时任务,生成搜索索引文件
		timer = new Timer(true);
		timer.schedule(new SearchIndex(context),0,60*60*1000);//0表示任务无延迟，5*1000表示每隔5秒执行任务，60*60*1000表示一个小时；
	}
	
	
	
	 

}